
package triangle;

import java.io.*;

public class Triangle {
	static boolean is_right_triangle;
	static String triangle_type;
	static BufferedReader stdin =  new BufferedReader ( new InputStreamReader( System.in ) );
	public static void main (String[] args) throws IOException
	{
	    String end;
	    boolean restart;
	    
	    String s1 = null, s2 = null, s3 = null;
	    
	    double    first, second, third;                
	    
	    do 
	    {
	    	System.out.println("Enter length of first side:");
	    	s1 = stdin.readLine();
		    first   = readSide(s1);
	
		    System.out.println("Enter length of second side:");
		    s2 = stdin.readLine();
		    second   = readSide(s2);
	
		    System.out.println("Enter length of third side:");
		    s3 = stdin.readLine();   
		    third   = readSide(s3);
	
		    if (isTriangle(first, second, third))
		    {
			    System.out.println(find_triangle_type(first, second, third));
			    
		    }
		    else
		    	System.out.println("Not a valid triangle");
		    
		    System.out.println("Restart (Y or N):");
		    end = stdin.readLine();
		    restart = restart(end);
	    }while (restart) ;
	    System.out.println("Good Bye!!!");
	}
	
	public static boolean restart(String end)
	{
		boolean restart = false;
		if (end.equalsIgnoreCase("Y"))
	    {	
	    	restart = true;
	    }
	    else
	    {
	    	restart = false;
	    }
		return restart;
	}
	public static boolean isTriangle(double first, double second, double third)
	{
		boolean retValue = true;
		
		if (first + second <= third)
			retValue = false;
		else if (second + third <= first)
			retValue = false;
		else if (third + first <= second)
			retValue = false;
		return retValue;
	}
	
	
	public static String find_triangle_type(double d, double e, double f)
	{
		if (	(
				(d == e) || (d == f) || (e == f) 
				) &&
				!(d == e && e == f))
		{
			triangle_type = "Isoceles";
		}
		
		if (d != e && e != f && d!=f)
		{
			triangle_type = "Scalene";
		}
		
		if (d == e && e == f)
		{
			triangle_type = "Equilateral";
		}
		
		if (is_right_triangle( d,  e,  f) == true)
		{
			return "Right " + triangle_type;
		}
		else 
		{
			return triangle_type;
		}
		
		
	}
	
	public static boolean is_right_triangle(double d, double e, double f)
	{
		is_right_triangle = false;
		if (
			(
			Math.pow(d,2)+((0.01)*(Math.pow(d,2))) >= (Math.pow(e, 2) + Math.pow(f, 2))
			&&
			(Math.pow(d,2))-((0.01)*(Math.pow(d,2))) <= (Math.pow(e, 2) + Math.pow(f, 2))
			)
		 || 
		 	(
		 	Math.pow(e,2)+((0.01)*(Math.pow(e,2))) >= (Math.pow(d, 2) + Math.pow(f, 2))
			&&
			(Math.pow(e,2))-((0.01)*(Math.pow(e,2))) <= (Math.pow(d, 2) + Math.pow(f, 2))
			)
		 || (
			Math.pow(f,2)+((0.01)*(Math.pow(f,2))) >= (Math.pow(e, 2) + Math.pow(d, 2))
			&&
			(Math.pow(f,2))-((0.01)*(Math.pow(f,2))) <= (Math.pow(e, 2) + Math.pow(d, 2))
					
			)
		 )
		{
			is_right_triangle = true;
		}
		return is_right_triangle;
		
	}
	
	public static double readSide(String side)
	{
		double s = 0;
		do
		{
			try
			{
				s = Double.parseDouble(side);
			}
			catch (Exception ex)
			{
				System.out.println("Invalid input.");
				System.out.println("Enter length of the side again:");
				try {
					side = stdin.readLine();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
			return s;
		}while(true);
	}
	
}